﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Sim.aspx.cs" Inherits="admin_Sim" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table border="0" cellspacing="0" cellpadding="0" width="100%">
    	<tr>
    		<td id="left" valign="top">
    		    <ul>    		        
    		        <li><a href="TaiKhoan.aspx">Thiết lập tài khoản</a></li>
    		        <li><a href="Sim.aspx">Thiết lập Sim</a></li>    		        
    		        <li><a href="Logout.aspx">Đăng xuất</a></li>
    		    </ul>
    		</td>
    		<td id="content" valign="top">
                <h2>Chỉnh sửa SIM</h2>
                <table border="0" cellspacing="0" cellpadding="0" width="100%">
                	<tr>
                		<td>
                		    
                		    Số sim: <asp:TextBox ID="txtSoSim" runat="server" Width="90px"></asp:TextBox>
                		    Giá: <asp:TextBox ID="txtGia" runat="server" Width="90px"></asp:TextBox>
                		    Loại:  <asp:DropDownList ID="ddLoai" runat="server" 
                                DataSourceID="SqlDataSource4" DataTextField="TenLoai" DataValueField="TID"></asp:DropDownList>
                            Mạng: <asp:DropDownList ID="ddMang" runat="server" 
                                DataSourceID="SqlDataSource5" DataTextField="TenNhaMang" DataValueField="MID"></asp:DropDownList>
                             <asp:Button ID="btnThemSim" runat="server" Text="Thêm" 
                                onclick="btnThemSim_Click" />
                             <asp:Button ID="btnCancel" runat="server" Text="Hủy" 
                                Visible="false" onclick="btnCancel_Click" />
                                <br /><br />
                            <asp:GridView ID="gvSim" runat="server" AllowPaging="True" AllowSorting="True" 
                                AutoGenerateColumns="False" CellPadding="5" DataSourceID="SqlDataSource3" 
                                ForeColor="#333333" GridLines="None">
                                <RowStyle BackColor="#EFF3FB" />
                                <Columns>
                                    <asp:BoundField DataField="STT" HeaderText="STT" ReadOnly="True" 
                                        SortExpression="STT" />
                                    <asp:BoundField DataField="SID" HeaderText="SID" InsertVisible="False" 
                                        ReadOnly="True" SortExpression="SID" />
                                    <asp:BoundField DataField="SoSim" HeaderText="Số Sim" SortExpression="SoSim" />
                                    <asp:BoundField DataField="Gia" HeaderText="Giá" SortExpression="Gia" />
                                    <asp:BoundField DataField="TenLoai" HeaderText="Loại" 
                                        SortExpression="TenLoai" />
                                    <asp:BoundField DataField="TenNhaMang" HeaderText="Mạng" 
                                        SortExpression="TenNhaMang" />
                                    <asp:BoundField DataField="TID" HeaderText="TID" InsertVisible="False" 
                                        ReadOnly="True" SortExpression="TID" Visible="False" />
                                    <asp:TemplateField>
                                    <ItemTemplate>
                                        <input type="button" value="Edit" onclick="location.href='Sim.aspx?edit=<%#Eval("SID") %>'" />                                        
                                        <asp:Button ID="LinkButton1" Runat="server" OnClientClick="return confirm('Chắc chắn xóa?');"
                                            CommandName="Delete" Text="Delete"></asp:Button>                                         
                                    </ItemTemplate>
                                    
                                    
                                    </asp:TemplateField>
                                     
                                </Columns>
                                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                                <EditRowStyle BackColor="#2461BF" />
                                <AlternatingRowStyle BackColor="White" />
                            </asp:GridView>
                            <asp:SqlDataSource ID="SqlDataSource4" runat="server" 
                                ConnectionString="<%$ ConnectionStrings:simDBConnectionString %>" 
                                SelectCommand="SELECT * FROM [tLoaiSim]"></asp:SqlDataSource>
                            
                            <asp:SqlDataSource ID="SqlDataSource5" runat="server" 
                                ConnectionString="<%$ ConnectionStrings:simDBConnectionString %>" 
                                SelectCommand="SELECT [MID], [TenNhaMang] FROM [tNhaMang]">
                            </asp:SqlDataSource>
                           
                            
                            <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
                                ConnectionString="<%$ ConnectionStrings:simDBConnectionString %>" 
                                SelectCommand="sp_tSim_getSim" SelectCommandType="StoredProcedure" 
                                DeleteCommand="DELETE FROM [tSim] WHERE [SID] = @original_SID" 
                                OldValuesParameterFormatString="original_{0}"
                                ConflictDetection="CompareAllValues" >
                                <DeleteParameters>
                                    <asp:Parameter Name="original_SID" Type="Int32" />                                   
                                </DeleteParameters>
                              </asp:SqlDataSource>
                        </td>
                	</tr>
                </table>
                <hr />
                <h2>Nhà Mạng & Phân Loại</h2>                
                <table border="0" cellspacing="0" cellpadding="0" width="100%">
                	<tr>
                		<td>
                		    Tên nhà mạng: <asp:TextBox ID="txtNhaMang" runat="server" Width="100px"></asp:TextBox>
                            Logo: 
                            <asp:TextBox ID="txtLogo" runat="server" ></asp:TextBox>
                            <asp:Button ID="txtThemNhaMang" runat="server" Text="Thêm" 
                                onclick="txtThemNhaMang_Click" />
                            <br /><br />
                            <asp:GridView ID="gvNhaMang" runat="server" AllowPaging="True" 
                                AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" 
                                DataKeyNames="MID" DataSourceID="SqlDataSource1" ForeColor="#333333" 
                                GridLines="None">
                                <RowStyle BackColor="#EFF3FB" />
                                <Columns>
                                    <asp:BoundField DataField="MID" HeaderText="MID" InsertVisible="False" 
                                        ReadOnly="True" SortExpression="MID" />
                                    <asp:BoundField DataField="TenNhaMang" HeaderText="Tên nhà mạng" 
                                        SortExpression="TenNhaMang" />
                                    <asp:BoundField DataField="LogoPath" HeaderText="Đường dẫn logo" 
                                        SortExpression="LogoPath" />
                                    <asp:CommandField ShowEditButton="True" ButtonType="Button" />
                                    <asp:TemplateField><ItemTemplate>
                                        <asp:Button ID="LinkButton1" Runat="server" OnClientClick="return confirm('Chắc chắn xóa?');"
                                            CommandName="Delete" Text="Delete"></asp:Button>
                                    </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                                <EditRowStyle BackColor="#2461BF" />
                                <AlternatingRowStyle BackColor="White" />
                            </asp:GridView>
                		    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                                ConflictDetection="CompareAllValues" 
                                ConnectionString="<%$ ConnectionStrings:simDBConnectionString %>" 
                                DeleteCommand="DELETE FROM [tNhaMang] WHERE [MID] = @original_MID AND [TenNhaMang] = @original_TenNhaMang AND (([LogoPath] = @original_LogoPath) OR ([LogoPath] IS NULL AND @original_LogoPath IS NULL))" 
                                InsertCommand="INSERT INTO [tNhaMang] ([TenNhaMang], [LogoPath]) VALUES (@TenNhaMang, @LogoPath)" 
                                OldValuesParameterFormatString="original_{0}" 
                                SelectCommand="SELECT * FROM [tNhaMang]" 
                                UpdateCommand="UPDATE [tNhaMang] SET [TenNhaMang] = @TenNhaMang, [LogoPath] = @LogoPath WHERE [MID] = @original_MID AND [TenNhaMang] = @original_TenNhaMang AND (([LogoPath] = @original_LogoPath) OR ([LogoPath] IS NULL AND @original_LogoPath IS NULL))">
                                <DeleteParameters>
                                    <asp:Parameter Name="original_MID" Type="Int32" />
                                    <asp:Parameter Name="original_TenNhaMang" Type="String" />
                                    <asp:Parameter Name="original_LogoPath" Type="String" />
                                </DeleteParameters>
                                <UpdateParameters>
                                    <asp:Parameter Name="TenNhaMang" Type="String" />
                                    <asp:Parameter Name="LogoPath" Type="String" />
                                    <asp:Parameter Name="original_MID" Type="Int32" />
                                    <asp:Parameter Name="original_TenNhaMang" Type="String" />
                                    <asp:Parameter Name="original_LogoPath" Type="String" />
                                </UpdateParameters>
                                <InsertParameters>
                                    <asp:Parameter Name="TenNhaMang" Type="String" />
                                    <asp:Parameter Name="LogoPath" Type="String" />
                                </InsertParameters>
                            </asp:SqlDataSource>
                		</td>
                		
                		<td valign="top">
                		    Tên Loại: <asp:TextBox ID="txtLoai" runat="server" ></asp:TextBox>                            
                            <asp:Button ID="btnThemLoai" runat="server" Text="Thêm" onclick="btnThemLoai_Click" 
                                 />
                            <br /><br />
                            
                            <asp:GridView ID="gvLoaiSim" runat="server" AllowPaging="True" 
                                AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" 
                                DataKeyNames="TID" DataSourceID="SqlDataSource2" ForeColor="#333333" 
                                GridLines="None">
                                <RowStyle BackColor="#EFF3FB" />
                                <Columns>
                                    <asp:BoundField DataField="TID" HeaderText="TID" InsertVisible="False" 
                                        ReadOnly="True" SortExpression="TID" />
                                    <asp:BoundField DataField="TenLoai" HeaderText="Tên Loại" 
                                        SortExpression="TenLoai" />
                                    <asp:CommandField ButtonType="Button" ShowEditButton="True" />
                                    <asp:TemplateField><ItemTemplate>
                                        <asp:Button ID="LinkButton1" Runat="server" OnClientClick="return confirm('Chắc chắn xóa?');"
                                            CommandName="Delete" Text="Delete"></asp:Button>
                                    </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                                <EditRowStyle BackColor="#2461BF" />
                                <AlternatingRowStyle BackColor="White" />
                            </asp:GridView>
                		    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                                ConflictDetection="CompareAllValues" 
                                ConnectionString="<%$ ConnectionStrings:simDBConnectionString %>" 
                                DeleteCommand="DELETE FROM [tLoaiSim] WHERE [TID] = @original_TID AND [TenLoai] = @original_TenLoai" 
                                InsertCommand="INSERT INTO [tLoaiSim] ([TenLoai]) VALUES (@TenLoai)" 
                                OldValuesParameterFormatString="original_{0}" 
                                SelectCommand="SELECT * FROM [tLoaiSim]" 
                                UpdateCommand="UPDATE [tLoaiSim] SET [TenLoai] = @TenLoai WHERE [TID] = @original_TID AND [TenLoai] = @original_TenLoai">
                                <DeleteParameters>
                                    <asp:Parameter Name="original_TID" Type="Int32" />
                                    <asp:Parameter Name="original_TenLoai" Type="String" />
                                </DeleteParameters>
                                <UpdateParameters>
                                    <asp:Parameter Name="TenLoai" Type="String" />
                                    <asp:Parameter Name="original_TID" Type="Int32" />
                                    <asp:Parameter Name="original_TenLoai" Type="String" />
                                </UpdateParameters>
                                <InsertParameters>
                                    <asp:Parameter Name="TenLoai" Type="String" />
                                </InsertParameters>
                            </asp:SqlDataSource>
                		</td>
                	</tr>
                </table>
    		</td>
    	</tr>
    </table>
    </div>
    </form>
</body>
</html>
